// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// RESTRICTED USE SOURCE CODE
// http://www.magic-software.com/License/restricted.pdf

#include "MgcNode.h"
#include "MgcRenderer.h"

MgcImplementRTTI(MgcRenderer,MgcObject);

//---------------------------------------------------------------------------
MgcRenderer::MgcRenderer (int iWidth, int iHeight)
    :
    m_kBackgroundColor(MgcColor::WHITE)
{
    m_iWidth = iWidth;
    m_iHeight = iHeight;
    m_iQuantity = m_iWidth*m_iHeight;
}
//---------------------------------------------------------------------------
MgcRenderer::MgcRenderer ()
    :
    m_kBackgroundColor(MgcColor::WHITE)
{
    m_iWidth = 0;
    m_iHeight = 0;
    m_iQuantity = 0;
}
//---------------------------------------------------------------------------
MgcRenderer::~MgcRenderer ()
{
    m_spkCamera = 0;
}
//---------------------------------------------------------------------------
MgcCameraPtr MgcRenderer::SetCamera (MgcCamera* pkCamera)
{
    MgcCamera* pkSave = m_spkCamera;
    m_spkCamera = pkCamera;
    return pkSave;
}
//---------------------------------------------------------------------------
void MgcRenderer::Draw (MgcNode* pkScene)
{
    pkScene->OnDraw(*this);
}
//---------------------------------------------------------------------------
void MgcRenderer::InitializeState ()
{
    MgcRenderState** apkState = MgcRenderState::GetDefaultStates();

    MgcRenderState* pkState = apkState[MgcRenderState::RS_ALPHA];
    SetAlphaState((MgcAlphaState*)pkState);

    pkState = apkState[MgcRenderState::RS_DITHER];
    SetDitherState((MgcDitherState*)pkState);

    pkState = apkState[MgcRenderState::RS_FOG];
    SetFogState((MgcFogState*)pkState);

    pkState = apkState[MgcRenderState::RS_LIGHT];
    SetLightState((MgcLightState*)pkState);

    pkState = apkState[MgcRenderState::RS_MATERIAL];
    SetMaterialState((MgcMaterialState*)pkState);

    pkState = apkState[MgcRenderState::RS_SHADE];
    SetShadeState((MgcShadeState*)pkState);

    pkState = apkState[MgcRenderState::RS_TEXTURE];
    SetTextureState((MgcTextureState*)pkState);

    pkState = apkState[MgcRenderState::RS_VERTEXCOLOR];
    SetVertexColorState((MgcVertexColorState*)pkState);

    pkState = apkState[MgcRenderState::RS_WIREFRAME];
    SetWireframeState((MgcWireframeState*)pkState);

    pkState = apkState[MgcRenderState::RS_ZBUFFER];
    SetZBufferState((MgcZBufferState*)pkState);
}
//----------------------------------------------------------------------------
void MgcRenderer::SetState (const MgcRenderStatePtr aspkState[])
{
    MgcRenderState* pkState = aspkState[MgcRenderState::RS_ALPHA];
    SetAlphaState((MgcAlphaState*)pkState);

    pkState = aspkState[MgcRenderState::RS_DITHER];
    SetDitherState((MgcDitherState*)pkState);

    pkState = aspkState[MgcRenderState::RS_FOG];
    SetFogState((MgcFogState*)pkState);

    pkState = aspkState[MgcRenderState::RS_LIGHT];
    SetLightState((MgcLightState*)pkState);

    pkState = aspkState[MgcRenderState::RS_MATERIAL];
    SetMaterialState((MgcMaterialState*)pkState);

    pkState = aspkState[MgcRenderState::RS_SHADE];
    SetShadeState((MgcShadeState*)pkState);

    pkState = aspkState[MgcRenderState::RS_TEXTURE];
    SetTextureState((MgcTextureState*)pkState);

    pkState = aspkState[MgcRenderState::RS_VERTEXCOLOR];
    SetVertexColorState((MgcVertexColorState*)pkState);

    pkState = aspkState[MgcRenderState::RS_WIREFRAME];
    SetWireframeState((MgcWireframeState*)pkState);

    pkState = aspkState[MgcRenderState::RS_ZBUFFER];
    SetZBufferState((MgcZBufferState*)pkState);
}
//----------------------------------------------------------------------------
